﻿/*
* main.cxx
*
*  Created on: 2014-9-28
*      Author: Fifi Lyu
*/

#include "zpsoe/zlog.h"
#include <cstdlib>
#include <iostream>

using namespace zpsoe::zlog;

int main(int argc, char* argv[]) {
    cout << "\n---------- TestCase1: 输出到 stdout ----------" << endl;
    G_LogConfig.level = LOG_TRACE;
    G_LogConfig.output_to = LOGOUTPUTSTREAM_STDOUT;

    print_log(LOG_TRACE, "TestCase.%d: This is %s log message", 1, "LOG_TRACE");
    print_log(LOG_DEBUG, "TestCase.%d: This is %s log message", 1, "LOG_DEBUG");
    print_log(LOG_INFO, "TestCase.%d: This is %s log message", 1, "LOG_INFO");
    print_log(LOG_WARN, "TestCase.%d: This is %s log message", 1, "LOG_WARN");
    print_log(LOG_ERROR, "TestCase.%d: This is %s log message", 1, "LOG_ERROR");
    print_log(LOG_FATAL, "TestCase.%d: This is %s log message\n", 1, "LOG_FATAL");
    // 不会输出任何日志
    print_log(LOG_OFF, "TestCase.%d: This is %s log message", 1, "LOG_OFF");


    cout << "\n---------- TestCase1: 输出到 stderr ----------" << endl;
    G_LogConfig.level = LOG_TRACE;
    G_LogConfig.output_to = LOGOUTPUTSTREAM_STDERR;

    print_log(LOG_TRACE, "TestCase.%d: This is %s log message", 2, "LOG_TRACE");
    print_log(LOG_DEBUG, "TestCase.%d: This is %s log message", 2, "LOG_DEBUG");
    print_log(LOG_INFO, "TestCase.%d: This is %s log message", 2, "LOG_INFO");
    print_log(LOG_WARN, "TestCase.%d: This is %s log message", 2, "LOG_WARN");
    print_log(LOG_ERROR, "TestCase.%d: This is %s log message", 2, "LOG_ERROR");
    print_log(LOG_FATAL, "TestCase.%d: This is %s log message\n", 2, "LOG_FATAL");
    // 不会输出任何日志
    print_log(LOG_OFF, "TestCase.%d: This is %s log message", 2, "LOG_OFF");


    cout << "\n---------- TestCase1: 输出到 文件 test.log.txt 日志最大大小：10k ----------" << endl;
    G_LogConfig.level = LOG_TRACE;
    G_LogConfig.output_to = LOGOUTPUTSTREAM_FILE;
    // 当日志文件大小超过限制时，日志文件内容将被覆盖写入
    G_LogConfig.max_byte = 10000;  // 10kb
    G_LogConfig.path = "test.log.txt";

    print_log(LOG_TRACE, "TestCase.%d: This is %s log message", 3, "LOG_TRACE");
    print_log(LOG_DEBUG, "TestCase.%d: This is %s log message", 3, "LOG_DEBUG");
    print_log(LOG_INFO, "TestCase.%d: This is %s log message", 3, "LOG_INFO");
    print_log(LOG_WARN, "TestCase.%d: This is %s log message", 3, "LOG_WARN");
    print_log(LOG_ERROR, "TestCase.%d: This is %s log message", 3, "LOG_ERROR");
    print_log(LOG_FATAL, "TestCase.%d: This is %s log message\n", 3, "LOG_FATAL");
    // 不会输出任何日志
    print_log(LOG_OFF, "TestCase.%d: This is %s log message", 2, "LOG_OFF");

    return EXIT_SUCCESS;
}

